/// 
/// MaDAson - Toolkit for Model Driven Software Development
/// 
/// Copyright [2006] Marcus Lankenau
/// 
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///  
///     http://www.apache.org/licenses/LICENSE-2.0
///  
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
/// 

using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Core;
using NUnit.Framework;

namespace Madason.MetaModel.Interfaces.Tests
{
	[TestFixture]
	public class TestImportXmi11Association : TestImportXmi11Base
	{		
		string xmiAssociation =
			@"<XMI.content xmlns:UML=""href://org.omg/UML/1.3"">" +
			@"<UML:Class xmi.id=""UMLClass.3"" name=""Company"" visibility=""public"" isSpecification=""false"" namespace=""UMLPackage.2"" isRoot=""false"" isLeaf=""false"" isAbstract=""false"" participant=""UMLAssociationEnd.7"" isActive=""false""/>" +
			@"<UML:Class xmi.id=""UMLClass.4"" name=""Person"" visibility=""public"" isSpecification=""false"" namespace=""UMLPackage.2"" isRoot=""false"" isLeaf=""false"" isAbstract=""false"" participant=""UMLAssociationEnd.6"" isActive=""false""/>" +
			@"<UML:Association xmi.id=""UMLAssociation.5"" name="""" visibility=""public"" isSpecification=""false"" namespace=""UMLPackage.2"">" +
			@"  <UML:Association.connection>" +
			@"    <UML:AssociationEnd xmi.id=""UMLAssociationEnd.6"" name=""Employee"" visibility=""public"" isSpecification=""false"" isNavigable=""true"" ordering=""unordered"" aggregation=""none"" targetScope=""instance"" changeability=""changeable"" association=""UMLAssociation.5"" type=""UMLClass.4"">" +
			@"      <UML:AssociationEnd.multiplicity>" +
			@"        <UML:Multiplicity xmi.id=""X.8"">" +
			@"          <UML:Multiplicity.range>" +
			@"            <UML:MultiplicityRange xmi.id=""X.9"" lower=""1"" upper=""-1"" multiplicity=""X.8""/>" +
			@"          </UML:Multiplicity.range>" +
			@"        </UML:Multiplicity>" +
			@"      </UML:AssociationEnd.multiplicity>" +
			@"    </UML:AssociationEnd>" +
			@"    <UML:AssociationEnd xmi.id=""UMLAssociationEnd.7"" name=""Employer"" visibility=""public"" isSpecification=""false"" isNavigable=""true"" ordering=""unordered"" aggregation=""none"" targetScope=""instance"" changeability=""changeable"" association=""UMLAssociation.5"" type=""UMLClass.3"">" +
			@"      <UML:AssociationEnd.multiplicity>" +
			@"        <UML:Multiplicity xmi.id=""X.10"">" +
			@"          <UML:Multiplicity.range>" +
			@"            <UML:MultiplicityRange xmi.id=""X.11"" lower=""0"" upper=""1"" multiplicity=""X.10""/>" +
			@"          </UML:Multiplicity.range>" +
			@"        </UML:Multiplicity>" +
			@"      </UML:AssociationEnd.multiplicity>" +
			@"    </UML:AssociationEnd>" +
			@"  </UML:Association.connection>" +
			@"</UML:Association>" +
			@"</XMI.content>";
		
		[Test]
		public void TestAssociation()
		{			
			Model model = LoadModel(xmiAssociation);
			Assert.AreEqual(2, model.Classes.Count);
			Class person = model.Classes[1];
			Class company = model.Classes[0];

			Assert.AreEqual(1, person.Associations.Count);
			Assert.AreEqual(1, company.Associations.Count);			
		}

		[Test]
		public void TestAssociationRoles()
		{
			Model model = LoadModel(xmiAssociation);
			Assert.AreEqual(2, model.Classes.Count);
			Class person = model.Classes[1];
			Class company = model.Classes[0];

			Assert.AreEqual(1, person.Associations.Count);
			Assert.AreEqual(1, company.Associations.Count);

			Assert.AreEqual("Employer", person.Associations[0].Name);
			Assert.AreEqual("Employee", company.Associations[0].Name);			
		}

		[Test]
		public void TestAssociationMultiplicity()
		{

			Model model = LoadModel(xmiAssociation);
			Assert.AreEqual(2, model.Classes.Count);
			Class person = model.Classes[1];
			Class company = model.Classes[0];

			Assert.AreEqual(1, person.Associations.Count);
			Assert.AreEqual(1, company.Associations.Count);

			Assert.AreEqual(Cardinality.One, person.Associations[0].Cardinality);
			Assert.AreEqual(Cardinality.Many, company.Associations[0].Cardinality);			
		}

		[Test]
		public void TestAssociationTargetClass()
		{
			Model model = LoadModel(xmiAssociation);
			Assert.AreEqual(2, model.Classes.Count);
			Class person = model.Classes[1];
			Class company = model.Classes[0];

			Assert.AreEqual(1, person.Associations.Count);
			Assert.AreEqual(1, company.Associations.Count);

			Assert.AreEqual(company, person.Associations[0].TargetClass);
			Assert.AreEqual(person, company.Associations[0].TargetClass);			
		}
	}
}
